<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Returns the latency of this server in milliseconds</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="mongodb-driver-server.getinfo.html">« MongoDB\Driver\Server::getInfo</a></li>
      <li style="float: right;"><a href="mongodb-driver-server.getport.html">MongoDB\Driver\Server::getPort »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="class.mongodb-driver-server.html">MongoDB\Driver\Server</a></li>
    <li>Returns the latency of this server in milliseconds</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="mongodb-driver-server.getlatency" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">MongoDB\Driver\Server::getLatency</h1>
  <p class="verinfo">(mongodb &gt;=1.0.0)</p><p class="refpurpose"><span class="refname">MongoDB\Driver\Server::getLatency</span> &mdash; <span class="dc-title">Returns the latency of this server in milliseconds</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-mongodb-driver-server.getlatency-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">final</span> <span class="modifier">public</span> <span class="methodname"><strong>MongoDB\Driver\Server::getLatency</strong></span>(): <span class="type"><span class="type">?</span><span class="type">integer</span></span></div>

  <p class="para rdfs-comment">
   Returns the latency of this server in milliseconds. This is the client&#039;s
   measured
   <a href="https://github.com/mongodb/specifications/blob/master/source/server-discovery-and-monitoring/server-discovery-and-monitoring.rst#round-trip-time" class="link external">&raquo;&nbsp;round trip time</a>
   of a <code class="literal">hello</code> command.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-mongodb-driver-server.getlatency-parameters">
  <h3 class="title">参数</h3>
  <p class="para">此函数没有参数。</p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-mongodb-driver-server.getlatency-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   Returns the latency of this server in milliseconds, or <strong><code>null</code></strong> if no latency
   has been measured (e.g. client is connected to a load balancer).
  </p>
 </div>


 <div class="refsect1 errors" id="refsect1-mongodb-driver-server.getlatency-errors">
  <h3 class="title">错误／异常</h3>
  <ul class="simplelist">
   <li class="member">Throws <span class="classname"><a href="class.mongodb-driver-exception-invalidargumentexception.html" class="classname">MongoDB\Driver\Exception\InvalidArgumentException</a></span> on argument parsing errors.</li>
  </ul>
 </div>


 <div class="refsect1 changelog" id="refsect1-mongodb-driver-server.getlatency-changelog">
  <h3 class="title">更新日志</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>版本</th>
       <th>说明</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>PECL mongodb 1.11.0</td>
       <td>
        This method will return <strong><code>null</code></strong> if no latency has been measured. In
        earlier versions, an integer was always returned and an unset value
        might be reported as <code class="literal">-1</code>.
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-mongodb-driver-server.getlatency-examples">
  <h3 class="title">范例</h3>
  <div class="example" id="example-1347">
   <p><strong>示例 #1 <span class="function"><strong>MongoDB\Driver\Server::getLatency()</strong></span> example</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br />$manager&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">MongoDB</span><span style="color: #007700">\</span><span style="color: #0000BB">Driver</span><span style="color: #007700">\</span><span style="color: #0000BB">Manager</span><span style="color: #007700">(</span><span style="color: #DD0000">"mongodb://localhost:27017/"</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$rp&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">MongoDB</span><span style="color: #007700">\</span><span style="color: #0000BB">Driver</span><span style="color: #007700">\</span><span style="color: #0000BB">ReadPreference</span><span style="color: #007700">(</span><span style="color: #0000BB">MongoDB</span><span style="color: #007700">\</span><span style="color: #0000BB">Driver</span><span style="color: #007700">\</span><span style="color: #0000BB">ReadPreference</span><span style="color: #007700">::</span><span style="color: #0000BB">RP_PRIMARY</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$server&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$manager</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">selectServer</span><span style="color: #007700">(</span><span style="color: #0000BB">$rp</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$server</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getLatency</span><span style="color: #007700">());<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

   <div class="example-contents"><p>以上例程的输出类似于：</p></div>
   <div class="example-contents screen">
<div class="cdata"><pre>
int(592)
</pre></div>
   </div>
  </div>
 </div>


 <div class="refsect1 seealso" id="refsect1-mongodb-driver-server.getlatency-seealso">
  <h3 class="title">参见</h3>
  <ul class="simplelist">
   <li class="member"><span class="function"><a href="mongodb-driver-server.getinfo.html" class="function" rel="rdfs-seeAlso">MongoDB\Driver\Server::getInfo()</a> - Returns an array of information describing this server</span></li>
   <li class="member"><span class="function"><strong>MongoDB\Driver\ServerDescription::getRoundTripTime()</strong></span></li>
   <li class="member"><a href="https://github.com/mongodb/specifications/blob/master/source/server-discovery-and-monitoring/server-discovery-and-monitoring.rst" class="link external">&raquo;&nbsp;Server Discovery and Monitoring Specification</a></li>
  </ul>
 </div>


</div></div></div></body></html>